home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / HeadA.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  10.8 KB  |  376 lines

  1. class classes.enemy.HeadA
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var colorR;
  9.    var trans;
  10.    var colorTrans;
  11.    var f2;
  12.    var dir;
  13.    var axis;
  14.    var xDest;
  15.    var yDest;
  16.    var ep;
  17.    var oldDir;
  18.    var xMov = 0;
  19.    var yMov = 0;
  20.    var xMovT = 0;
  21.    var yMovT = 0;
  22.    var speedOrig = 6;
  23.    var speed = 6;
  24.    var xDestMet = false;
  25.    var yDestMet = false;
  26.    var c = 0;
  27.    var life = 3;
  28.    var nc = 0;
  29.    var xA = 0;
  30.    var yA = 0;
  31.    var nudging = false;
  32.    var power = 10;
  33.    var hc = 0;
  34.    var flashing = false;
  35.    var flashC = 0;
  36.    var Name = "headA";
  37.    function HeadA(px, py, pmoveScript, pid)
  38.    {
  39.       this.x = px;
  40.       this.y = py;
  41.       this.moveScript = pmoveScript.slice();
  42.       this.id = pid;
  43.       _root.d = _root.d + 1;
  44.       this.clip = _root.attachMovie("headA","headA" + this.id + "Clip",_root.d + 50000);
  45.       this.clip._x = this.x;
  46.       this.clip._y = this.y;
  47.       this.speed *= _root.dif.speed;
  48.       this.speedOrig = this.speed;
  49.       this.speedVar();
  50.       this.colorR = _root.randRange(-10,30);
  51.       this.trans = new flash.geom.Transform(this.clip);
  52.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  53.       this.trans.colorTransform = this.colorTrans;
  54.       this.parseMoveScript();
  55.       if(_root.flashing)
  56.       {
  57.          this.flashing = true;
  58.          _root.flashing = false;
  59.       }
  60.       _root.stats.created = _root.stats.created + 1;
  61.    }
  62.    function nudge(pxA, pyA, pscale)
  63.    {
  64.       this.nc = 0;
  65.       this.nudging = true;
  66.       var _loc2_ = pscale / 100;
  67.       this.xA = pxA * _loc2_;
  68.       this.yA = pyA * _loc2_;
  69.    }
  70.    function bombed(num)
  71.    {
  72.       this.f2 = "death";
  73.    }
  74.    function speedVar()
  75.    {
  76.       if(random(3) == 1)
  77.       {
  78.          this.speed *= _root.randRange2(0.9998,1.0002);
  79.       }
  80.    }
  81.    function parseMoveScript()
  82.    {
  83.       this.dir = this.moveScript[0];
  84.       if(this.dir == "break")
  85.       {
  86.          delete this.moveScript;
  87.          this[this.axis + "MovT"] = 0;
  88.          this.f2 = "wander";
  89.          if(random(10) > 2)
  90.          {
  91.             this.dir = _root.getDir(this.x,this.y);
  92.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  93.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  94.             this.speedVar();
  95.          }
  96.          else
  97.          {
  98.             this.axis = random(10) <= 4 ? "y" : "x";
  99.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  100.             this.getDirString();
  101.          }
  102.       }
  103.       else
  104.       {
  105.          this[this.axis + "MovT"] = 0;
  106.          this.f2 = "gotoXYDest";
  107.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  108.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  109.          this.speedVar();
  110.          if(this.dir == "L" || this.dir == "U")
  111.          {
  112.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  113.          }
  114.          else
  115.          {
  116.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  117.          }
  118.          this.moveScript.splice(0,2);
  119.       }
  120.    }
  121.    function gotoXYDest()
  122.    {
  123.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  124.       {
  125.          if(this.axis == "x")
  126.          {
  127.             this.x = this.xDest;
  128.          }
  129.          else
  130.          {
  131.             this.y = this.yDest;
  132.          }
  133.          this.parseMoveScript();
  134.       }
  135.    }
  136.    function getDirString()
  137.    {
  138.       if(this.xMovT < -1)
  139.       {
  140.          this.dir = "L";
  141.       }
  142.       else if(this.xMovT > 1)
  143.       {
  144.          this.dir = "R";
  145.       }
  146.       else if(this.yMovT > 1)
  147.       {
  148.          this.dir = "D";
  149.       }
  150.       else if(this.yMovT < -1)
  151.       {
  152.          this.dir = "U";
  153.       }
  154.    }
  155.    function wander()
  156.    {
  157.       if(random(100) > 85 || (this.x > 950 || this.x < 50 || this.y < 50 || this.y > 550))
  158.       {
  159.          if(random(20) > 18)
  160.          {
  161.             this[this.axis + "MovT"] = 0;
  162.             this.f2 = "wait";
  163.             this.c = 0;
  164.             this.ep = _root.randRange(30,120);
  165.          }
  166.          else if(random(10) > 1)
  167.          {
  168.             this.dir = _root.getDir(this.x,this.y);
  169.             this[this.axis + "MovT"] = 0;
  170.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  171.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  172.             this.speedVar();
  173.          }
  174.          else
  175.          {
  176.             this[this.axis + "MovT"] = 0;
  177.             this.axis = random(10) <= 4 ? "y" : "x";
  178.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  179.             this.getDirString();
  180.          }
  181.       }
  182.    }
  183.    function wait()
  184.    {
  185.       this.c = this.c + 1;
  186.       if(this.c == this.ep)
  187.       {
  188.          this.f2 = "wander";
  189.          if(random(10) > 2 + _root.dif.wander)
  190.          {
  191.             this.dir = _root.getDir(this.x,this.y);
  192.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  193.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  194.             this.speedVar();
  195.          }
  196.          else
  197.          {
  198.             this.axis = random(10) <= 4 ? "y" : "x";
  199.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  200.             this.getDirString();
  201.          }
  202.       }
  203.       if(random(100) > 95)
  204.       {
  205.          var _loc3_ = ["L","R","F"];
  206.          this.dir = _loc3_[random(_loc3_.length)];
  207.       }
  208.    }
  209.    function attacking()
  210.    {
  211.    }
  212.    function death()
  213.    {
  214.       _root.stats.destroyed = _root.stats.destroyed + 1;
  215.       _root.stats.score += 500;
  216.       _root.powerUp(this.x,this.y,95);
  217.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(60,80),_root.randRange(75,100),"Green"]);
  218.       var _loc3_ = 0;
  219.       var _loc4_ = random(3);
  220.       while(_loc3_ < _loc4_)
  221.       {
  222.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"headA","Green"]);
  223.          _loc3_ = _loc3_ + 1;
  224.       }
  225.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"green"]);
  226.       _root.audio.playLevel4("headX" + (random(3) + 1),_root.randRange(15,25));
  227.       _root.removeChar("headA" + this.id);
  228.       this.f2 = "";
  229.    }
  230.    function death2()
  231.    {
  232.       _root.removeChar("headA" + this.id);
  233.       this.f2 = "";
  234.    }
  235.    function main()
  236.    {
  237.       if(this.flashing)
  238.       {
  239.          this.flashC = this.flashC + 1;
  240.          var _loc8_ = 275 - this.flashC * 10;
  241.          this.colorTrans.greenOffset = _loc8_;
  242.          this.colorTrans.redOffset = _loc8_;
  243.          this.colorTrans.blueOffset = _loc8_;
  244.          this.trans.colorTransform = this.colorTrans;
  245.          if(this.flashC == 27)
  246.          {
  247.             this.colorTrans.greenOffset = 0;
  248.             this.colorTrans.redOffset = 0;
  249.             this.colorTrans.blueOffset = 0;
  250.             this.trans.colorTransform = this.colorTrans;
  251.             delete this.flashing;
  252.             delete this.flashC;
  253.          }
  254.       }
  255.       this[this.f2]();
  256.       if(this.oldDir != this.dir)
  257.       {
  258.          if(this.oldDir == undefined || this.dir == "F")
  259.          {
  260.             this.clip.body.eyes.gotoAndStop(this.dir);
  261.          }
  262.          else if(this.dir == "U" || this.dir == "D")
  263.          {
  264.             this.clip.body.eyes.gotoAndStop(this.oldDir);
  265.          }
  266.          else if(random(3) > 0)
  267.          {
  268.             if(this.dir == "R")
  269.             {
  270.                this.clip.body.eyes.gotoAndPlay("LtoR");
  271.             }
  272.             else
  273.             {
  274.                this.clip.body.eyes.gotoAndPlay("RtoL");
  275.             }
  276.          }
  277.          else
  278.          {
  279.             this.clip.body.eyes.gotoAndPlay("spin" + this.dir);
  280.          }
  281.       }
  282.       this.oldDir = this.dir;
  283.       if(this.nudging)
  284.       {
  285.          this.xA *= 0.5;
  286.          this.yA *= 0.5;
  287.          this.nc = this.nc + 1;
  288.          _loc8_ = 255 - this.nc * 17;
  289.          this.colorTrans.greenOffset = _loc8_;
  290.          this.colorTrans.redOffset = _loc8_ / 2;
  291.          this.trans.colorTransform = this.colorTrans;
  292.          if(this.nc == 15)
  293.          {
  294.             this.xA = this.yA = 0;
  295.             this.nudging = false;
  296.             this.colorTrans.greenOffset = this.colorR;
  297.             this.colorTrans.redOffset = this.colorR;
  298.             this.trans.colorTransform = this.colorTrans;
  299.          }
  300.       }
  301.       var _loc4_ = 0;
  302.       var _loc7_ = _root.broShots.length;
  303.       while(_loc4_ < _loc7_)
  304.       {
  305.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  306.          if(this.clip.hitTest(_root[_loc6_]))
  307.          {
  308.             var _loc3_ = _root.broShots[_loc4_];
  309.             var _loc5_ = this.life;
  310.             this.life -= _root[_loc3_].power;
  311.             if(this.life < 1)
  312.             {
  313.                this.f2 = "death";
  314.             }
  315.             else
  316.             {
  317.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  318.                _root.audio.playLevel4("headHit" + (random(4) + 1),_root.randRange(18,26));
  319.                this[this.axis + "MovT"] = 0;
  320.                this.axis = random(10) <= 4 ? "y" : "x";
  321.                this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  322.                this.getDirString();
  323.             }
  324.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  325.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  326.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  327.             _root[_loc3_].hit(_loc5_);
  328.             break;
  329.          }
  330.          _loc4_ = _loc4_ + 1;
  331.       }
  332.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  333.       {
  334.          _root[_root.char].stealCoins(5);
  335.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  336.          this.f2 = "death";
  337.       }
  338.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  339.       {
  340.          this.f2 = "death2";
  341.       }
  342.       if(this.xMovT < this.xMov)
  343.       {
  344.          this.xMov -= 0.15;
  345.       }
  346.       else if(this.xMovT > this.xMov)
  347.       {
  348.          this.xMov += 0.15;
  349.       }
  350.       else
  351.       {
  352.          this.xMov = this.xMovT;
  353.       }
  354.       if(this.yMovT < this.yMov)
  355.       {
  356.          this.yMov -= 0.15;
  357.       }
  358.       else if(this.yMovT > this.yMov)
  359.       {
  360.          this.yMov += 0.15;
  361.       }
  362.       else
  363.       {
  364.          this.yMov = this.yMovT;
  365.       }
  366.       if(random(100) > 98)
  367.       {
  368.          this.clip.body.eyes.clip.gotoAndPlay("blink");
  369.       }
  370.       this.x += this.xMov + this.xA;
  371.       this.y += this.yMov + this.yA + 0.5 * Math.sin(this.hc += 0.1);
  372.       this.clip._x = this.x;
  373.       this.clip._y = this.y;
  374.    }
  375. }
  376.